<?php require_once('../../g-config/konek.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php?stat=logout";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO plug_review (id, id_menu, konten_ke, plugin, sett) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['id_menu'], "text"),
                       GetSQLValueString($_POST['konten_ke'], "int"),
                       GetSQLValueString($_POST['plugin'], "text"),
                       GetSQLValueString($_POST['sett'], "int"));

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($insertSQL, $konek) or die(mysql_error());

  $insertGoTo = "plugin_review.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_admin = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_admin = $_SESSION['MM_Username'];
}
mysql_select_db($database_konek, $konek);
$query_admin = sprintf("SELECT * FROM data_user WHERE nama_user = %s", GetSQLValueString($colname_admin, "text"));
$admin = mysql_query($query_admin, $konek) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);

if ($_GET['p']<>""){
$nama_plug=strtolower($_GET['p']);
if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$nama_plug."'"))==1) {

mysql_select_db($database_konek, $konek);
$query_plugin_list = "SELECT * FROM $nama_plug ORDER BY id DESC";
$plugin_list = mysql_query($query_plugin_list, $konek) or die(mysql_error());
$row_plugin_list = mysql_fetch_assoc($plugin_list);
$totalRows_plugin_list = mysql_num_rows($plugin_list);



} else {
	echo "Plugin $nama_plug Belum Terinstall, <a href='pluginview.php?p=$nama_plug' target='_blank'> install plug</a> ";	
}
}

$colname_plug_review = "-1";
if (isset($_GET['id_set'])) {
  $colname_plug_review = $_GET['id_set'];
}
$colname_plug_review2 = "-1";
if (isset($_GET['kolomke'])) {
  $colname_plug_review2 = $_GET['kolomke'];
}
mysql_select_db($database_konek, $konek);
$query_plug_review = sprintf("SELECT * FROM plug_review WHERE id_menu = %s AND konten_ke = %s ORDER BY id ASC", GetSQLValueString($colname_plug_review, "text"),GetSQLValueString($colname_plug_review2, "int"));
$plug_review = mysql_query($query_plug_review, $konek) or die(mysql_error());
$row_plug_review = mysql_fetch_assoc($plug_review);
$totalRows_plug_review = mysql_num_rows($plug_review);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Skin support example</title>
<!-- Bootstrap -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="../awesome/css/font-awesome.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body style="background:#fff">

<?php
function daftar_file($dir)
{
    if(is_dir($dir))
    {
        if($handle = opendir($dir))
        {
    //tampilkan semua file dalam folder kecuali
            while(($file = readdir($handle)) !== false)
            {
				if(strlen($file)>8)
				$judul=substr($file,0,10)." ..";
				else $judul=$file;
				if($file<>".." and $file<>"." and $file<>"uploadzip.php")
        echo '<div style="margin:5px; float:left" align="center"><a href="plugin_review.php?id_set='.$_GET['id_set'].'&amp;kolomke='.$_GET['kolomke'].'&amp;p='.$file.'"><img src="'.$dir.$file.'/image.png" width="100px" height="100px"  /><br />'.$judul.'</a></div>';
            }
            closedir($handle);
        }
    }
}
//cara menggunakan
?>
<?php if ($totalRows_plug_review > 0) { // Show if recordset not empty ?>
  <table id="example-datatable" class="table table-bordered table-hover dataTable" aria-describedby="example-datatable_info" >
    <tr>
      <td width="50">id</td>
      <td>Plugin</td>
      <td>Judul</td>
      <td width="50">Action</td>
      </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_plug_review['id']; ?></td>
        <td><?php echo $row_plug_review['plugin']; ?></td>
        <td><?php 
mysql_select_db($database_konek, $konek);
$query_past = "SELECT * FROM $row_plug_review[plugin] WHERE id = $row_plug_review[sett]";
$past = mysql_query($query_past, $konek) or die(mysql_error());
$row_past = mysql_fetch_assoc($past);
$totalRows_past = mysql_num_rows($past);
echo $row_past['judul'];
			 ?></td>
        <td><a href="del_plug_review.php?id_set=<?php echo $_GET['id_set'] ?>&amp;kolomke=<?php echo $_GET['kolomke'] ?>&amp;p=<?php echo $_GET['p'] ?>&amp;idplug_review=<?php echo $row_plug_review['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a></td>
      </tr>
      <?php } while ($row_plug_review = mysql_fetch_assoc($plug_review)); ?>
  </table>
  <?php } // Show if recordset not empty ?>
<br />
<br />

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><?php if ($_GET['p']==""){
daftar_file("../../g-konten/plugin/");
	} else {
		if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$nama_plug."'"))==1) { 
		if ($totalRows_plugin_list>0) {
?>
     
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        <table align="left">
          <tr valign="baseline">
            <td>
            <strong>All List Module <a href="pluginview.php?p=<?php echo $_GET['p'] ?>" target="_blank" ><?php echo $_GET['p'] ?></a></strong><br />
<br />

<?php 
do {  
?>
  <label>
    <input type="radio" name="sett" value="<?php echo $row_plugin_list['id']?>" id="type_1" />
    <?php echo $row_plugin_list['judul']?></label><br />
                
              <?php
} while ($row_plugin_list = mysql_fetch_assoc($plugin_list));
?></td>
          </tr>
          <tr valign="baseline">
            <td><input type="submit" value="Add Module" class="btn btn-default" />  
              <a href="plugin_review.php?id_set=<?php echo $_GET['id_set'] ?>&kolomke=<?php echo $_GET['kolomke'] ?>"> &lt;&lt; back</a></td>
          </tr>
        </table>
        <input type="hidden" name="id" value="" />
        <input type="hidden" name="id_menu" value="<?php echo $_GET['id_set'] ?>" />
        <input type="hidden" name="konten_ke" value="<?php echo $_GET['kolomke'] ?>" />
        <input type="hidden" name="plugin" value="<?php echo $nama_plug ?>" />
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
    <p>&nbsp;</p>
    <?php } else { ?>Plugin Masih Kosong  <a href="plugin_review.php?id_set=<?php echo $_GET['id_set'] ?>&kolomke=<?php echo $_GET['kolomke'] ?>"> &lt;&lt; back</a><?php } } } ?></td>
  </tr>
</table>

<a href="javascript:void(0)" id="to-top" style="display: none;"><i class="fa fa-angle-up"></i></a>
 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="../js/bootstrap.min.js"></script>
</body>
</html>
<?php
mysql_free_result($plug_review);



mysql_free_result($admin);



?>
